package com.cyh.core.framework.aop;

import java.lang.reflect.Method;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;

/**
 * @Author: yanhang_chen
 * @Date: 2020-09-15 17:17:54
 */
// 关闭注解开启AOP
//@Aspect
//@Component
public class RepositoryAspect {

    @Pointcut("execution(* com.cyh.*.*.repository.*.*(..))")
    public void PoinCut(){}

    @Around(value = "PoinCut()")
    public Object aroundExec(ProceedingJoinPoint joinPoint) throws Throwable {
        Object res = null;
        long time = System.currentTimeMillis();
        try {

            MethodSignature signature = (MethodSignature)joinPoint.getSignature();
            Method method=signature.getMethod();
            String methodName=signature.getName();
            // 加入repository的拦截，可对要保存/插入的参数进行操作
            // 例如更新更改时间，插入最后更新人等
            if(methodName.indexOf("save") != -1){
                Object[] objs=joinPoint.getArgs();
                for (Object obj:objs
                     ) {
                }
            }
            res =  joinPoint.proceed();
            time = System.currentTimeMillis() - time;
            return res;
        } finally {

        }
    }

}
